<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Admin\Auth;
use DB;

class AuthController extends Controller
{
    //
    public function index(){
    	// SELECT t1.* ,t2.auth_name as parent_name FROM auth as t1 LEFT JOIN auth as t2 on t1.pid=t2.id;
    	$data = DB::table('auth as t1')->select('t1.*','t2.auth_name as parent_name')->leftJoin('auth as t2', 't1.pid' ,'=','t2.id')->get();
    	return view('admin.auth.index',compact('data'));

    }
    public function add(Request $request){

    	if ($request->isMethod('post')) {
    		$data = $request->except('_token');
    		$result = Auth::insert($data);
    		return $result ? '1' : '0'; 
		}else{
			$parents = Auth::where('pid', '=', '0')->get();
			return view('admin.auth.add',compact('parents'));
		}

		
    }			
}
